﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ContestMeter.Common;

namespace ContestMeter.Teacher.UI
{
    public class Record : NotifyPropertyChanged
    {
        const string ParticipantPropertyName = "Participant";
        private Participant _participant;
        public Participant Participant
        {
            get { return _participant; }
            set
            {
                if (_participant != value)
                {
                    _participant = value;
                    OnPropertyChanged(ParticipantPropertyName);
                    OnPropertyChanged("FullName");
                }
            }
        }

        const string SolutionsPropertyName = "Solutions";
        private IEnumerable<Solution> _solutions;
        public IEnumerable<Solution> Solutions
        {
            get { return _solutions; }
            set
            {
                if (_solutions != value)
                {
                    _solutions = value;
                    OnPropertyChanged(SolutionsPropertyName);
                    OnPropertyChanged("Score");
                }
            }
        }

        const string FolderPropertyName = "Folder";
        private string _folder;
        public string Folder
        {
            get { return _folder; }
            set
            {
                if (_folder != value)
                {
                    _folder = value;
                    OnPropertyChanged(FolderPropertyName);
                }
            }
        }

        public string FullName
        {
            get
            {
                if (Participant != null)
                {
                    return string.Format("{0} {1} {2}", Participant.LastName, Participant.FirstName, Participant.MiddleName);
                }

                return "";
            }
        }

        public int Score
        {
            get
            {
                if (Participant != null && Participant.Solutions != null)
                {
                    return (from sol in Participant.Solutions select sol.WeightedScore).Sum(); 
                }

                return 0;
            }
        }

        const string IsPendingPropertyName = "IsPending";
        private bool _isPending;
        public bool IsPending
        {
            get { return _isPending; }
            set
            {
                if (_isPending != value)
                {
                    _isPending = value;
                    OnPropertyChanged(IsPendingPropertyName);
                    OnPropertyChanged("Score");
                }
            }
        }
    }
}
